package morning.cat.curator.sample;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * XXX
 *
 * @author mengzhang6
 * @date 2018/11/30 10:31
 */
public class CuratorClientSampleTest {

    static CuratorClientSample sample = null;

    @BeforeClass
    public static void before() {
        sample = new CuratorClientSample("127.0.0.1:2181");
        sample.init();
    }

    @AfterClass
    public static void after() {
        sample.destroy();
    }

    @Test
    public void test1() throws Exception {
        String path = "/morningcat";
        sample.createNode(path, "hello ZK", null);

        System.out.println(sample.checkNodeExists(path));
        System.out.println(sample.getValue(path));

        sample.setValue(path, "Beijing");
        System.out.println(sample.checkNodeExists(path));
        System.out.println(sample.getValue(path));

        sample.setValue(path, null);
        System.out.println(sample.checkNodeExists(path));
        System.out.println(sample.getValue(path));

        sample.deleteNode(path);
        System.out.println(sample.checkNodeExists(path));
        System.out.println(sample.getValue(path));
    }

    @Test
    public void test2() throws Exception {
        String path = "/morningcat";

        System.out.println(sample.createNode(path, "hello ZK", null));

        System.out.println(sample.checkNodeExists(path));
        System.out.println(sample.getValue(path));

    }


}
